<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>欢乐谷</title>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="/new/layui/css/layui.css">
    <link rel="stylesheet" href="/new/css/entertain/x-admin.css" media="all">
    <script type="text/javascript" src="/new/js/entertain/xadmin.js"></script>
</head>
<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3" style="line-height:50%"></i></a>
</div>
<button class="layui-btn" onclick="add()"><i class=" layui-icon layui-icon-add-circle"></i>添加</button>
<a href="/manager/excel?a=2" class="layui-btn"><i class="layui-icon layui-icon-table"></i>excel导出</a>
<table class="layui-table" lay-even lay-skin="nob">
    <thead>
    <th>ID</th>
    <th>设施名</th>
    <th>简介</th>
    <th>点赞数</th>
    <th>所属主题</th>
    <th>状态</th>
    <th>操作</th>
    </thead>
    <tbody>
    <tr th:each="x:${facility}">
        <td th:text="${x.facilityId}"></td>
        <td th:text="${x.facilityName}"></td>
        <td th:text="${x.facilityContent}"></td>
        <td th:text="${x.facilityGreat}"></td>
        <td>
            <ul th:each="y:${x.entertainmentList}" style="list-style-type: none">
                <li th:text="${y.entertainmentName}" ></li>
            </ul>
        </td>
        <td th:if="${x.facilityStatus==0}"><span>已启用</span></td>
        <td th:if="${x.facilityStatus==1}"><span>已停用</span></td>
        <td th:if="${x.facilityStatus==2}"><span>升级中</span></td>
        <td th:if="${x.facilityStatus==0}">
            <a class="layui-icon layui-icon-logout" onclick="member_stop(this)" href="javascript:;" title="停用"></a>
            <a class="layui-icon layui-icon-upload-circle" onclick="member_stop(this)" href="javascript:;" title="升级"></a>
            <a>|</a>
            <a title="编辑"  onclick="update(this)" href="javascript:;">
                <i class="layui-icon layui-icon-edit"></i>
            </a>
            <a title="删除" onclick="del(this,'要删除的id')" href="javascript:;">
                <i class="layui-icon layui-icon-delete"></i>
            </a>
        </td>
        <td th:if="${x.facilityStatus==1}">
            <a class="layui-icon layui-icon-circle-dot" onclick="member_stop(this)" href="javascript:;" title="启用"></a>
            <a class="layui-icon layui-icon-upload-circle" onclick="member_stop(this)" href="javascript:;" title="升级"></a>
            <a>|</a>
            <a title="编辑"  onclick="update(this)" href="javascript:;">
                <i class="layui-icon layui-icon-edit"></i>
            </a>
            <a title="删除" onclick="del(this,'要删除的id')" href="javascript:;">
                <i class="layui-icon layui-icon-delete"></i>
            </a>
        </td>
        <td th:if="${x.facilityStatus==2}">
            <a class="layui-icon layui-icon-circle-dot" onclick="member_stop(this)" href="javascript:;" title="启用"></a>
            <a class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop" onclick="member_stop(this)" href="javascript:;" title="升级中"></a>
            <a>|</a>
            <a title="编辑"  onclick="update(this)" href="javascript:;">
                <i class="layui-icon layui-icon-edit"></i>
            </a>
            <a title="删除" onclick="del(this,'要删除的id')" href="javascript:;">
                <i class="layui-icon layui-icon-delete"></i>
            </a>
        </td>
    </tr>
    </tbody>
</table>
<script src="/new/layui/layui.js" charset="utf-8">
</script>
<script src="/new/js/entertain/x-layui.js" charset="utf-8">
</script>
<script>
    /*用户-停用*/
    function member_stop(obj) {
        //获取要更改用户的详细uId
        var tel = $(obj).parents("tr").find("td").eq(0).text()
        //layer.alert(tel)
        layer.confirm('确认要更改状态吗？', function (index) {
            var facility = {};
            facility.facilityId = $(obj).parents("tr").find("td").eq(0).text();
            if ($(obj).attr("title") == "停用") {
                facility.facilityStatus = 1;
                $(obj).attr("title", "启用")
                $(obj).parents("tr").find("td").eq(5).find("span").text("已停用")
                $(obj).removeClass("layui-icon-logout").addClass("layui-icon-circle-dot")
            } else if($(obj).attr("title") == "启用") {
                facility.facilityStatus = 0;
                $(obj).attr("title", "停用")
                $(obj).parents("tr").find("td").eq(5).find("span").text("已启用")
                $(obj).removeClass("layui-icon-circle-dot").addClass("layui-icon-logout")
            }else if ($(obj).attr("title") == "升级"){
                facility.facilityStatus = 2;
                $(obj).attr("title", "完成")
                $(obj).parents("tr").find("td").eq(5).find("span").text("升级中")
                $(obj).removeClass("layui-icon-upload-circle").addClass("layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop")
                $(obj).parents("td").find("a").eq(0).attr("title", "启用")
                $(obj).parents("td").find("a").eq(0).removeClass().addClass("layui-icon layui-icon-circle-dot")
            }else {
                facility.facilityStatus = 1;
                $(obj).attr("title", "升级")
                $(obj).parents("tr").find("td").eq(5).find("span").text("已停用")
                $(obj).removeClass("layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop").addClass("layui-icon-upload-circle")
            }
            layer.close(index);

            $.ajax({
                url : "/manager/facilitystatus",
                type : "post",
                contentType: "application/json",
                data : JSON.stringify(facility),
                success : function (data) {
                    if (data.status == 200) {
                        layer.alert(data.message);
                    } else {
                        layer.alert(data.message);
                    }
                },
                error : function (data) {
                    layer.alert(data.responseText);
                }
            });
        });
    }
    /*用户-编辑*/
    function update(obj) {
        //获取要编辑用户的编号id
        var id=$(obj).parents("tr").find("td").eq(0).text();
        //layer.alert(id)
        //访问修改页面地址，把编号uId传过去
        var url ='/manager/facilitymodify?id='+id
        x_admin_show('设施修改',url)
    }
    function add() {
        x_admin_show('设施添加','/manager/addfacility')
    }
    /*用户-删除*/
    function del(obj){
        //获取要删除用户的编号staffId
        var id=$(obj).parents("tr").find("td").eq(0).text();
        //console.log(JSON.stringify(id));
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                url : "/manager/delfacility",
                type : "post",
                contentType: "application/json",
                data : JSON.stringify(id),
                success : function (data) {
                    if (data.status == 200) {
                        $(obj).parents("tr").remove();
                        layer.alert(data.message);
                    } else {
                        layer.alert(data.message);
                    }
                },
                error : function (data) {
                    layer.alert(data.responseText);
                }
            })
        })}

</script>
</body>
</html>